$(document).ready(
		function()
		{
			loadStats();
		});

function loadStats()
{
	$.ajax({
		type : "GET",
		url : "/cultu/admin/stats/communitystats",
		contentType : "application/json",
		dataType: "json",
		success: function(datas){
			console.log(datas);
			
			var drilldownSeries = [];
			
			$.each(datas.universes, function (value) {
				var universe = datas.universes[value];
                drilldownSeries.push({
                    name: universe.drilldown,
                    id: universe.drilldown,
                    data: universe.categoriesStat
                });
            });
			
			$('#container').highcharts({
                chart: {
                    type: 'pie'
                },
                title: {
                    text: 'Répartition des ventes entres les communautés.'
                },
                subtitle: {
                    text: 'Drilldown : activé'
                },
                plotOptions: {
                    series: {
                        dataLabels: {
                            enabled: true,
                            format: '{point.name}: {point.y:.1f}%'
                        }
                    }
                },

                tooltip: {
                    headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
                    pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>'
                }, 

                series: [{
                    name: 'Communautés',
                    colorByPoint: true,
                    data: datas.universes
                }],
                drilldown: {
                    series: drilldownSeries
                }
            });
		}
	});
	
	$.ajax({
		type : "GET",
		url : "/cultu/admin/stats/ordersevolution",
		contentType : "application/json",
		dataType: "json",
		success: function(datas){
			console.log(datas);
			
			$('#containerSales').highcharts({
	            chart: {
	                zoomType: 'x',
	                spacingRight: 20
	            },
	            title: {
	                text: "Evolution des ventes sur l'année"
	            },
	            subtitle: {
	                text: document.ontouchstart === undefined ?
	                    'Sélectionner une plage pour zoomer' : 'Sélectionner une plage pour zoomer'
	            },
	            xAxis: {
	                type: 'datetime',
	                maxZoom: 14 * 24 * 3600000, // fourteen days
	                title: {
	                    text: null
	                }
	            },
	            yAxis: {
	                title: {
	                    text: 'Nombre de ventes'
	                }
	            },
	            tooltip: {
	                shared: true
	            },
	            legend: {
	                enabled: false
	            },
	            plotOptions: {
	                area: {
	                    fillColor: {
	                        linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1},
	                        stops: [
	                            [0, Highcharts.getOptions().colors[0]],
	                            [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
	                        ]
	                    },
	                    lineWidth: 1,
	                    marker: {
	                        enabled: false
	                    },
	                    shadow: false,
	                    states: {
	                        hover: {
	                            lineWidth: 1
	                        }
	                    },
	                    threshold: null
	                }
	            },
	    
	            series: [{
	                type: 'area',
	                name: 'Vente',
	                pointInterval: 24 * 3600 * 1000,
	                pointStart: datas.startDate,
	                data:datas.datas
	            }]
            });
		}
	});
}